package health.lm.com.component_base.util;

import android.content.Context;
import android.media.MediaPlayer;

import health.lm.com.component_base.R;

/**
 * Created by Android Studio .
 * 作者：zhong
 * 日期：2019/1/9
 * 邮箱：15206394364@163.com
 * 介绍：音效播放工具类
 * 修订：====================
 */
public class PlayAudioHelper {
    public static final int GUZHANG = 1;
    public static final int RING = 2;
    public static final int BEEP = 3;

    private static PlayAudioHelper playAudioHelper;
    private MediaPlayer mediaPlayer;

    private PlayAudioHelper() {
    }

    public static PlayAudioHelper getInstance() {
        if (null == playAudioHelper) playAudioHelper = new PlayAudioHelper();
        return playAudioHelper;
    }

    public void play(Context context, int audio_type) {
        //资源
        int audioResource = 0;
        switch (audio_type) {
            case GUZHANG:
                audioResource = R.raw.guzhang;
                break;
            case RING:
                audioResource = R.raw.ring;
                break;
            case BEEP:
                audioResource = R.raw.zxing_beep;
                break;
        }
        if (audioResource == 0) return;
        mediaPlayer = MediaPlayer.create(context, audioResource);
        mediaPlayer.setOnCompletionListener(MediaPlayer::release);
        mediaPlayer.start();
    }
}
